home *** CD-ROM | disk | FTP | other *** search
/ Directorty Opus 5 - Magellan 2 / Opus 5 - Magellan 2.iso / Extras / D51_NUSource / Source / Singles / CDOpus.s next >
Text File  |  1996-01-06  |  34KB  |  781 lines

  1. *=- PROGRAM INFORMATION -=*************************************************************
  2. * CDOpus, ©1996 Leo Davidson                                  *
  3. *=====================================================================================*
  4. * Purpose: Conversion of the CDO.dopus5 and OCD.dopus5 scripts.                  *
  5. *       This program can CD to the path of the current DOpus5 source lister...     *
  6. *       ...or open a new lister with the same path as your shell.              *
  7. *      (...and it does and bunch of other usefull Shell<->DOpus things too...)     *
  8. ***************************************************************************************
  9. *   To Do: Make the HELP/S text pause when it fills up the shell window.          *
  10. *          See ASM:Routines/UnUsed/Window_Rows.s for my comments about this.          *
  11. ***************************************************************************************
  12.  
  13. *=- ASSEMBLE-TIME SWITCHES -=**********************************************************
  14. * Comment out to disable the effect(s) described.                                     *
  15. ***************************************************************************************
  16. ;Beta_Version        ; Include Debug-Labels, Beta messages, etc.
  17. ;Beta_Version_ARexx    ; Include runtime-info about ARexx messages sent.
  18. ;Test_Pool_On_OS3    ; Force use of non-ROM pool routines, even with OS3+.
  19. DOpus5_Error        ; Enable Error messages via DOpus5/"dopus request".
  20. ;No_Requesters        ; Disable all requester-based output.
  21.             ; All error messages will be sent to shell.
  22.             ; Will also turn off "Please insert volume XXX" reqs.
  23. Default_Req        ; Make requesters the default for error messages.
  24.  
  25. *=- VERSION INFORMATION -=*************************************************************
  26. * Things like versions numbers, dates, and the name of the program are all defined    *
  27. * here as macros to save having to edit the entire source code.                       *
  28. *=====================================================================================*
  29. * The version strings should conform to the style guide. (Even though I think it      *
  30. * isn't the best way to do it, it's a standard :-(  ).                                *
  31. ***************************************************************************************
  32. PROGNAM    MACRO                Program name.
  33.     dc.b    "CDOpus"        /No spaces!/
  34.     ENDM
  35. VERSION    MACRO                The version of the program.
  36.     dc.b    "1.7"            version.revision - /No leading zeros/
  37.     ENDM
  38. REVDATE    MACRO                Date of completion.
  39.     dc.b    "6.1.96"        DD.MM.YY - /No leading zeros/
  40.     ENDM
  41. REVDAT2    MACRO                Date of completion.
  42.     dc.b    "06-Jan-1996"        /Any format/ (Not in $VER string)
  43.     ENDM
  44. *=- ASSEMBLER INFORMATION/OPTIONS -=***************************************************
  45.     Section    Super_Main,Code        Assemble to Public Memory.
  46.     IFD    Beta_Version        -.
  47.     Opt    D+             |
  48.     Opt    hcln             |_ Debug info ON
  49.     ELSE                 |  for Beta Versions.
  50.     Opt    D-             |
  51.     ENDC                -'
  52. ***************************************************************************************
  53.     Bra    ProgBeg            Jump to the start of the program.
  54. ***************************************************************************************
  55. VerStr    Dc.b    "$VER: "        -.
  56.     PROGNAM                 |
  57.     IFD    Beta_Version         |
  58.     Dc.b    "_DEBUG"         |
  59.     ENDC                 |_ For 2.0+ Version Command
  60.     Dc.b    " "             |  (At the top to make "Version"
  61. ActVer    VERSION                 |  find it quicker!)
  62.     Dc.b    " ("             |
  63.     REVDATE                 |
  64.     Dc.b    ")",0            -'
  65.     Even
  66. ;=====================================================================================;
  67. ;    Include    Asm:Include/Nudel_Constants.i
  68. ;
  69. ;    include    dos/dos.i
  70. ;    include    dos/var.i
  71. ;    include    exec/types.i
  72. ;    include    exec/nodes.i
  73. ;    include    exec/memory.i
  74. ;    include    rexx/storage.i
  75. ;    include    intuition/intuition.i
  76. ;    include    intuition/intuitionbase.i
  77. ;    include    libraries/iffparse.i
  78. ;
  79. ;    include    ASM:LVO3.0/dos_lib.i
  80. ;    include    ASM:LVO3.0/exec_lib.i
  81. ;    include    ASM:LVO3.0/intuition_lib.i
  82. ;    include    ASM:LVO3.0/rexxsyslib_lib.i
  83. ;    include    ASM:LVO3.0/utility_lib.i
  84. ;    include    ASM:LVO3.0/iffparse_lib.i
  85. ;    include    ASM:LVO3.0/mathieeedoubbas_lib.i
  86. ;    include    ASM:LVO3.0/graphics_lib.i
  87.  
  88.     Include    Nudel_Symbols.gs
  89. ***************************************************************************************
  90. * The Variables (Address Equates for Space allocated at program start)                *
  91. ***************************************************************************************
  92.     RSReset
  93.     IFND    No_Requesters
  94. ;=====================================================================================;
  95. N_EasyStruct    Equ    __RS        ;- EasyStruct for EasyRequest ----------------;
  96. ;=====================================================================================;
  97. N_ES_Length    Rs.l    1        Length of the structure.
  98. N_ES_Flags    Rs.l    1        Flags (not currently supported).
  99. N_ES_Title    Rs.l    1        Ptr to NullTerm Title Text.
  100. N_ES_Body    Rs.l    1        Ptr to NullTerm Body Text.
  101. N_ES_Gadgets    Rs.l    1        Prt to Gadget(s) Texts.
  102. N_EasyStruct_Len    Equ    (__RS)-N_EasyStruct
  103.     ENDC
  104.  
  105. ;=====================================================================================;
  106. ; Nudel Info-Block Stuff                                  ;
  107. ;=====================================================================================;
  108. FakeNIB        Rs.b    NIB_SizeOf    ;- Fake NIB for setting pseudo-filenames -----;
  109. FakeNIB_Adrs    Rs.l    1        Address of FakeNIB (saves a few "lea"'s).
  110. Active_NIB    Rs.l    1        Ptr to currently "Active" NIB, or null.
  111. Base_NIB    Rs.l    1        Ptr to base NIB in linked list, or null.
  112. Last_NIB    Rs.l    1        Ptr to last NIB in linked list, or null.
  113. CAction        Rs.l    1        Ptr to current "Action" error message.
  114. ;-------------------------------------------------------------------------------------;
  115. CD_NIB        Rs.l    1        NIB for locking of new CurrentDir
  116. ;=====================================================================================;
  117.  
  118. ;=====================================================================================;
  119. ; READARGS() STUFF                                      ;
  120. ;=====================================================================================;
  121. RDA_Rtn        Rs.l    1        Pointer to returned RDArgs structure
  122. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  123. RDA_Array    Equ    __RS        Array of longwords matching template
  124. RDA_Template    Equ    *
  125. RexxPort_K    Rs.l    1
  126.         Dc.b    "RP=REXXPORT/K,"
  127. Help_S        Rs.l    1
  128.         Dc.b    "HELP/S,"
  129. Quiet_S        Rs.l    1
  130.         Dc.b    "QUIET/S,"
  131. OpenLister_S    Rs.l    1
  132.         Dc.b    "OL=OPENLISTER/S,"
  133. ReadSource_S    Rs.l    1
  134.         Dc.b    "RS=READSOURCE/S,"
  135. ReadDest_S    Rs.l    1
  136.         Dc.b    "RD=READDEST/S,"
  137. DoAction_S    Rs.l    1
  138.         Dc.b    "DA=DOACTION/S,"
  139. NoFront_S    Rs.l    1
  140.         Dc.b    "NOFRONT/S,"
  141. NoNew_S        Rs.l    1
  142.         Dc.b    "NONEW/S,"
  143. Dir_K        Rs.l    1
  144.         Dc.b    "DIR=PATH/K,"
  145. Source_S    Rs.l    1
  146.         Dc.b    "SOURCE/S,"
  147. Dest_S        Rs.l    1
  148.         Dc.b    "DEST/S,"
  149. Lock_S        Rs.l    1
  150.         Dc.b    "LOCK/S,"
  151. Dimensions_K    Rs.l    1
  152.         Dc.b    "POS=DIMENSIONS/K,"
  153. ActPat_K    Rs.l    1
  154.         Dc.b    "PAT=ACTPAT/K,"
  155. ActCom_K    Rs.l    1
  156.         Dc.b    "COM=ACTCOM/K,"
  157. ActClose_S    Rs.l    1
  158.         Dc.b    "ACTCLOSE/S,"
  159. VarSource_S    Rs.l    1
  160.         Dc.b    "VARSOURCE/S,"
  161. VarDest_S    Rs.l    1
  162.         Dc.b    "VARDEST/S,"
  163. Global_S    Rs.l    1
  164.         Dc.b    "GLOBAL/S"
  165. RDA_Temp_Len    Equ    *-RDA_Template
  166.         Dc.b    0
  167.         Even
  168. ; Pseudo-Switch (setup in "Setup" routine).
  169. NoReq_S        Rs.l    1
  170.  
  171. ;=====================================================================================;
  172. ; OPEN_LIBRARIES STRUCTURES                                  ;
  173. ;=====================================================================================;
  174. LibBases_Start    Equ    __RS
  175. LibData_Start    Equ    *
  176. ; NOTE: The open_lib_error routine requires lib-versions < 100
  177. N_DOSBase    Rs.l    1
  178. DOSName_Ptr    Dc.l    N_DOSName-LibNames_Start
  179. DOSVers        Dc.l    37
  180. N_RexBase    Rs.l    1
  181. RexName_Ptr    Dc.l    N_RexName-LibNames_Start
  182. RexVers        Dc.l    0
  183.     IFND    No_Requesters
  184. N_IntBase    Rs.l    1
  185. IntBase_Ptr    Dc.l    N_IntName-LibNames_Start
  186. IntVers        Dc.l    37
  187.     ENDC
  188. LibBases_Finish    Equ    __RS
  189. NumLibs    Equ    (LibBases_Finish-LibBases_Start)/4
  190. ;-------------------------------------------------------------------------------------;
  191. LibNames_Start    Equ    *
  192. N_DOSName    DOSNAME
  193. N_RexName    REXXSYSLIBNAME
  194.     IFND    No_Requesters
  195. N_IntName    INTNAME        Required by Open_Libraries_Error rtn.
  196.     ENDC
  197.     Even
  198. ;=====================================================================================;
  199. ; FLAG BYTES                                          ;
  200. ;=====================================================================================;
  201. STD_F_1        Rs.b    1        Standard files.
  202. EVEN_F_1    Rs.b    1        (Here as an Even)
  203. ;=====================================================================================;
  204. ; VARIOUS DATA                                          ;
  205. ;=====================================================================================;
  206. DosRtnC        Rs.l    1        Return code for DOS. (-> d0 at end)
  207. ;=====================================================================================;
  208. ; RawDoFmt() Stuff                                      ;
  209. ;=====================================================================================;
  210. ;    IFD    DATA_RAWDOFMT
  211. RDF_Size    Rs.l    1        Size of RawDoFmt() buffer.
  212. RDF_Adrs    Rs.l    1        Address of RawDoFmt() buffer.
  213. RDF_Array    Equ    __RS
  214. RDF_1_Long    Rs.l    1        -.
  215. RDF_2_Long    Rs.l    1         |_ DataArray
  216. RDF_3_Long    Rs.l    1         |  for RawDoFmt()
  217. RDF_4_Long    Rs.l    1        -'
  218. ;    ENDC
  219. ;=====================================================================================;
  220. ; VARIOUS ADDRESS-POINTERS                                  ;
  221. ;=====================================================================================;
  222. StarStk        Rs.l    1        Original Stack Pointer.
  223. PoolHead    Rs.l    1        Header for program's memory pool.
  224. CLI_Hdl        Rs.l    1        Output CLI (or whatever) handle.
  225. NudelPort    Rs.l    1        Pointer to our MsgPort.
  226. NudelRexxMsg    Rs.l    1        Pointer to our RexxMsg.
  227. CRexxPort    Rs.l    1        Ptr to name of current Rexx host to talk to.
  228. ;=====================================================================================;
  229. ; TEMP STORAGE                                          ;
  230. ;=====================================================================================;
  231. Buffer1Len    Equ    1024
  232. Buffer1        Rs.b    Buffer1Len    Buffer for anything
  233. Buffer2Len    Equ    1024
  234. Buffer2        Rs.b    Buffer2Len    Buffer for anything
  235.     IFD    Beta_Version_ARexx
  236. BufferALen    Equ    1024
  237. BufferA        Rs.b    BufferALen    Buffer for ARexx beta messages.
  238.     ENDC
  239. PathBuffer1Len    Equ    512
  240. PathBuffer1    Rs.b    PathBuffer1Len
  241. Source_HandleLen Equ    42
  242. Source_Handle    Rs.b    Source_HandleLen
  243. Temp001        Rs.l    1        -._ For temp storage
  244. Temp002        Rs.l    1        -'  in routines.
  245. ;=====================================================================================;
  246. NULLEND        Equ    __RS        ;- Overlays Start Here -----------------------;
  247. ;=====================================================================================;
  248. ;=====================================================================================;
  249. LENVARS        Equ    __RS        ;- End of variables/overlays -----------------;
  250. ;=====================================================================================;
  251.  
  252. *=- MAIN PROGRAM -=********************************************************************
  253. * Calls the subroutines.                                  *
  254. ***************************************************************************************
  255. ProgBeg    Bsr.s    Setup            Allocate Mem and initialize stuff.
  256.     Bsr    Help            Send help text, if requested.
  257.     Bsr.s    Choose_Routine        Call the appropriate routine.
  258.     Bra    Finish            Close/Deallocate everything and exit.
  259. ***************************************************************************************
  260. Choose_Routine
  261.     Tst.l    OpenLister_S(a5)
  262.     Beq.s    Choose_S1
  263.     Bra    Get_CD_And_Open_Do_It_OpenLister
  264. Choose_S1
  265.     Tst.l    ReadSource_S(a5)
  266.     Beq.s    Choose_S2
  267.     Bra    Get_CD_And_Open_Do_It_ReadSource
  268. Choose_S2
  269.     Tst.l    ReadDest_S(a5)
  270.     Beq.s    Choose_S3
  271.     Bra    Get_CD_And_Open_Do_It_ReadDest
  272. Choose_S3
  273.     Tst.l    VarSource_S(a5)
  274.     Beq.s    Choose_S4
  275.     Bra    Set_Source_Env_Do_It
  276. Choose_S4
  277.     Tst.l    VarDest_S(a5)
  278.     Beq.s    Choose_S5
  279.     Bra    Set_Dest_Env_Do_It
  280. Choose_S5
  281.     Tst.l    DoAction_S(a5)
  282.     Beq.s    Choose_S6
  283.     Bra    Do_Action_Do_It
  284. Choose_S6
  285.     Bra    Get_Path_And_Change_Do_It
  286.  
  287. *=- SETUP -=***************************************************************************
  288. * Allocate Memory, Open Libraries, Parse Commandline, etc                  *
  289. * This MUST be the first Subroutine run.                          *
  290. ***************************************************************************************
  291. Setup    Move.l    #MEMF_PUBLIC!MEMF_CLEAR,d0    Public, Cleared mem.
  292.     Move.l    #5120,d1            Puddle size = 5k.
  293.     Move.l    #5120,d2            Thresh size = Puddle size.
  294.     Bsr    AsmCreatePool            Create this prog's mem pool.
  295.     Move.l    a0,-(SP)        Preserve PoolHeader
  296.     Bne.s    SGotMm1            -.
  297.     Addq.l    #4,a7             |_ If Allocation failed, Quick Exit.
  298.     Moveq    #RETURN_FAIL,d0         |  pool and do a quick exit.
  299.     RTS                -'
  300. SGotMm1    Move.l    #LENVARS,d0        Size of variables' memory
  301. ;;;;;;;    Move.l    a0,a0            PoolHeader to a0 for allocation.
  302.     Bsr    AsmAllocPooled        Allocate for the variables.
  303.     Move.l    (SP)+,a0        Restore PoolHeader
  304.     Move.l    d0,a5            Put variable/overlay address into A5
  305.     Tst.l    d0            (Moves to a? don't set CCR).
  306.     Bne.s    SGotMm2            -.
  307.     Bsr    AsmDeletePool         |
  308.     Addq.l    #4,a7             |- If Allocation failed, delete the
  309.     Moveq    #RETURN_FAIL,d0         |  pool and do a quick exit.
  310.     RTS                -'
  311. SGotMm2    Move.l    a0,PoolHead(a5)        Store header of memory pool.
  312.     Lea    FakeNIB(a5),a0        -._ Store address of FakeNIB(a5)
  313.     Move.l    a0,FakeNIB_Adrs(a5)    -'  for quick access later.
  314.     Move.l    #RETURN_OK,DosRtnC(a5)    Default DOS return code: "OK".
  315.     IFD    LENOVER
  316.     Lea    NULLEND(a5),a0        -.
  317.     Lea    Over01(pc),a1         |  Copy Overlay
  318.     Move.l    #(LENOVER/2)-1,d0     |- Backings onto
  319. OverPrL    Move.w    (a1)+,(a0)+         |  Overlay Space (word moves)
  320.     DBra    d0,OverPrL        -'
  321.     ENDC
  322. ;=====================================================================================;
  323.     Move.l    a7,StarStk(a5)        Store Stack Pointer
  324.     Addq.l    #4,StarStk(a5)        Compensate for this being a subrout.
  325.     IFND    No_Requesters
  326.     SetReqDefault            Set default to requester/shell.
  327.     ENDC
  328.     Bsr    Open_Libraries        Open libraries.
  329.     N_CallDOS    Output        -._ Get output Handle
  330.     Move.l    d0,CLI_Hdl(a5)        -'  (CLI window or whatever)
  331.  
  332. ;;;;;;;    Setup any non-zero default values for switch options here (below).
  333.     Bsr    RArgNor            Parse the commandline with ReadArgs
  334. ;=====================================================================================;
  335.     Tst.l    NoNew_S(a5)
  336.     Bne.s    NoNew_S_Skip
  337.     BSet    #SF1_NewListers,STD_F_1(a5)    Get(Source|Dest)Handle: Allow new listers
  338. NoNew_S_Skip
  339.     Tst.l    RexxPort_K(a5)            -._ If RexxPort not given on CmdLine,
  340.     Beq.s    Setup_RP_UseDef            -'  use the default one.
  341.     Move.l    RexxPort_K(a5),CRexxPort(a5)    Else, use RexxPort from CmdLine.
  342.     Bra.s    Setup_RP_UsedCmd
  343. Setup_RP_UseDef
  344.     Lea    Def_RexxPort(pc),a0
  345.     Move.l    a0,CRexxPort(a5)
  346. Setup_RP_UsedCmd
  347.  
  348.     Tst.l    ReadSource_S(a5)        -.
  349.     Bne.s    Dont_KillReqs             |
  350.     Tst.l    ReadDest_S(a5)             |_ If any of the Shell->Opus commands,
  351.     Bne.s    Dont_KillReqs             |  leave Error-Requesters ON.
  352.     Tst.l    OpenLister_S(a5)         |
  353.     Bne.s    Dont_KillReqs            -'
  354.     Move.l    #1,NoReq_S(a5)            Else, all Errors to the shell.
  355. Dont_KillReqs
  356.     Bra.s    CreateNudelPort        Create our MsgPort.
  357. ;;;;;;;    RTS for us.
  358.  
  359. Def_RexxPort
  360.     Dc.b    "DOPUS.1",0
  361.     Even
  362.  
  363. *=- FINISH -=**************************************************************************
  364. * Close Everything Down, Return Memory Etc to System and End Program              *
  365. *=====================================================================================*
  366. * All routines in this section MUST make sure that what they are about to free back   *
  367. * to the system has actually been taken in the first place! (With the exception of    *
  368. * the Main-Variable memory: if this could not be allocated the program will have      *
  369. * quit without calling Finish.)                                  *
  370. *=====================================================================================*
  371. * The Finish routine may be called from sub-routines at any level because the          *
  372. * original stack-pointer is restored so that RTS always quits the prog.              *
  373. ***************************************************************************************
  374. Finish
  375.     IFD    Beta_Version
  376.     Bsr_ErrorN    ErrAct_FinishBetaMsg(pc),#0
  377.     ENDC
  378.  
  379.     Bsr    DeleteNudelRexxMsg    Delete our RexxMsg (also clears arguments).
  380.     Bsr.s    DeleteNudelPort        Delete our MsgPort
  381.     Bsr    NIBs_DeleteAll        Delete all Nudel-Info-Blocks :-)
  382.     Bsr    FArgNor            Free the commandline related memory.
  383.     Bsr    Close_Libraries        Close all open libraries.
  384.     Move.l    StarStk(a5),a7        Ignore all Branches.
  385.     Move.l    DosRtnC(a5),-(SP)    Store DOS return code...
  386.     Bsr    LeoDeletePool        Free the entire memory pool.
  387.     Move.l    (SP)+,d0        Return code to d0 for DOS.
  388.     RTS                End Program
  389.  
  390.     IFD    Beta_Version
  391. ErrAct_FinishBetaMsg
  392.     Dc.b    "Finish routine run",0
  393.     Even
  394.     ENDC
  395.  
  396. *=- EXTERNAL SUB-ROUTINES -=***********************************************************
  397. * Sub-routines stored in external "library" files.                      *
  398. ***************************************************************************************
  399. ;=====================================================================================;
  400. ; OS Subroutines.                                      ;
  401. ;=====================================================================================;
  402. SYS_CLIRITE    ; Write text using CLI_Hdl(a5) as output handle.
  403. SYS_READARG    ; ReadArgs() routine.
  404. SYS_FREEARG    ; FreeArgs() routine.
  405. SYS_CHKCRTC    ; Check for ^C-Break and abort program if sent.
  406. SYS_PORTS    ; CreateMsgPort(), DeleteMsgPort() routines.
  407.     Include    ASM:Source/Routines/System.s
  408. ;=====================================================================================;
  409. ; Data Subroutines. (Number/String Handling, etc etc)                      ;
  410. ;=====================================================================================;
  411. DATA_NULLLEN    ; Calculate the length of a Null-Term String.
  412. DATA_COPYCN3    ; Copy chars with Null-Term, don't copy Null, no Length
  413. DATA_CHARCNT    ; Copy x chars with Null-Term
  414. DATA_CHARCOPNL    ; Copy x chars with Null-Term and specified terminator.
  415. DATA_NUM2ASC    ; Raw Number to ASCII conversion.
  416. DATA_RAWDOFMT    ; RawDoFmt() routine.
  417.     Include    ASM:Source/Routines/Data.s
  418. ;=====================================================================================;
  419. ; NudelInfoBlock Subroutines.                                  ;
  420. ;=====================================================================================;
  421. NIBR_UNLOCK    ; DOS/UnLock
  422. NIBR_LOCK    ; DOS/Lock
  423.     Include    ASM:Source/Routines/NIB.s
  424. ;=====================================================================================;
  425. ; Directory Opus 5 Subroutines.                                  ;
  426. ;=====================================================================================;
  427. DO5_GetSource    ; Get first source handle.
  428. DO5_GetDest    ; Get first destination handle.
  429. DO5_GetDest_OnlyToBuffer
  430. DO5_GetPath    ; Get the path of a lister.
  431. DO5_NewLister    ; Open a new lister.
  432. DO5_SetPath    ; Set (read) a new path into a lister.
  433. DO5_ListerSet    ; Generic "Lister Set..." routine.
  434. DO5_Command    ; Generic "command..." routine.
  435. DO5_GenError    ; Error message for things which really shouldn't go wrong.
  436. DO5_ListerWait    ; Wait for a lister to finish what it's doing.
  437. DO5_DOpusFront    ; Move the DOpus screen to the front, unless "NoFront/S"
  438. DO5_ListClose    ; Close a lister (does "wait" first).
  439.     Include    ASM:Source/Routines/DOpus5_ARexx.s
  440. ;=====================================================================================;
  441. ; Other routines.                                      ;
  442. ;=====================================================================================;
  443.     Include    ASM:Source/Routines/ARexx.s
  444.     Include    ASM:Source/Routines/Pool.s
  445.     Include    ASM:Source/Routines/OpenLibraries.s
  446.  
  447. *=- HELP -=****************************************************************************
  448. * Send the help text and exit if they gave that switch to ReadArgs()              *
  449. ***************************************************************************************
  450. Help    Tst.l    Help_S(a5)        Have they asked for help on cmd line?
  451.     Bne.s    Help_
  452.     RTS                If not, return.
  453. Help_
  454.     Lea    HelpTxt(pc),a0        -.
  455.     Move.l    #HelpLen,d3         |- Output Help Text.
  456.     Bsr    CLIRite            -'
  457.     Bra    Finish            Finish the program.
  458. ;-------------------------------------------------------------------------------------;
  459. HelpTxt    Dc.b    10,155,"32;1m"
  460.     PROGNAM
  461.     Dc.b    " "
  462.     VERSION
  463.     Dc.b    " ",155,"0m[",155,"33m"
  464.     REVDAT2
  465.     Dc.b    155,"0m] ",155,"32m- ",155,"33m© Leo ",155,"0m'Nudel'",155,"33m Davidson",155,"32m for Gods'Gift Utilities",155,"0m",10
  466.     Dc.b    10
  467.     Dc.b    155,"0;32mThis program can CD to the path of the current DOpus5 ",155,"4msource",155,"0;32m lister,",10
  468.     Dc.b    155,"0;32;1mor ",155,"0;32mread the shell's path into a new lister or the ",155,"4msource",155,"0;32m/",155,"4mdest",155,"0;32m lister.",10
  469.     Dc.b    155,"0m100% Assembler Code for AmigaOS 2 or above - ",155,"1mMay be made resident.",155,"0m",10
  470.     Dc.b    155,'0mType "CDOpus ?" for ReadArgs() command template.',10
  471.     Dc.b    10
  472.     Dc.b    155,"0;33mGeneric:",10
  473.     Dc.b    " ",155,"43;32m RexxPort   ",155,'0m  Specify a differnt port to talk to, instead of "DOPUS.1".',10
  474.     Dc.b    " ",155,"43;32m Help       ",155,"0m  ",155,"3mSwitch: ",155,"0mBrings up this text.",10
  475.     Dc.b    155,"0;33mModes:",10
  476.     Dc.b    " ",155,"43;32m <DEFAULT>  ",155,"0m  CD to 'source' lister's path.",10
  477.     Dc.b    " ",155,"43;32m OpenLister ",155,"0m  ",155,"3mSwitch: ",155,"0mRead path into a new lister.",10
  478.     Dc.b    " ",155,"43;32m DoAction   ",155,"0m  ",155,"3mSwitch: ",155,"0mRead path into new 'source' lister.",10
  479.     Dc.b    " ",155,"43;32m ReadSource ",155,"0m  ",155,"3mSwitch: ",155,"0mRead path into the 'source' lister.",10
  480.     Dc.b    " ",155,"43;32m ReadDest   ",155,"0m  ",155,"3mSwitch: ",155,"0mRead path into the 'dest' lister.",10
  481.     Dc.b    " ",155,"43;32m VarSource  ",155,"0m  ",155,"3mSwitch: ",155,"0mSet CDOSource environment variable.",10
  482.     Dc.b    " ",155,"43;32m VarDest    ",155,"0m  ",155,"3mSwitch: ",155,"0mSet CDODest environment variable.",10
  483.     Dc.b    155,"0;33mCD mode only:",10
  484.     Dc.b    " ",155,"43;32m Quiet      ",155,"0m  ",155,"3mSwitch: ",155,"0mDon't echo the new path to the shell.",10
  485.     Dc.b    155,"0;33mOpenLister/DoAction/Read modes only:",10
  486.     Dc.b    " ",155,"43;32m NoFront    ",155,"0m  ",155,"3mSwitch: ",155,"0mDon't pop the DOpus screen to front.",10
  487.     Dc.b    " ",155,"43;32m Dir        ",155,"0m  Specify a different directory to read, instead of <CD>.",10
  488.     Dc.b    155,"0;33mOpenLister mode only:",10
  489.     Dc.b    " ",155,"43;32m Source     ",155,"0m  ",155,"3mSwitch: ",155,"0mMake new lister the 'Source' lister.",10
  490.     Dc.b    " ",155,"43;32m Dest       ",155,"0m  ",155,"3mSwitch: ",155,"0mMake new lister the 'Dest' lister.",10
  491.     Dc.b    " ",155,"43;32m Lock       ",155,"0m  ",155,"3mSwitch: ",155,"0mLock new lister as Source/Dest.",10
  492.     Dc.b    155,"0;33mOpenLister/DoAction modes only:",10
  493.     Dc.b    " ",155,"43;32m Dimensions ",155,"0m  Specify different lister dimensions in x/y/w/h format.",10
  494.     Dc.b    155,"0;33mDoAction mode only:",10
  495.     Dc.b    " ",155,"43;32m ActPat     ",155,"0m  Specify files to select.",10
  496.     Dc.b    " ",155,"43;32m ActCom     ",155,"0m  Specify DOpus5 command to execute.",10
  497.     Dc.b    " ",155,"43;32m ActClose   ",155,"0m  ",155,"3mSwitch: ",155,"0mClose lister on completion.",10
  498.     Dc.b    155,"0;33mRead modes only:",10
  499.     Dc.b    " ",155,"43;32m NoNew      ",155,"0m  ",155,"3mSwitch: ",155,"0mDisable automatic openning of new listers.",10
  500.     Dc.b    155,"0;33mVar mode only:",10
  501.     Dc.b    " ",155,"43;32m Global     ",155,"0m  ",155,"3mSwitch: ",155,"0mSet global variable instead of local.",10
  502.     Dc.b    10
  503. HelpLen    Equ    *-HelpTxt
  504.     Even
  505.  
  506. ***************************************************************************************
  507. * Routine for getting the Source Lister's path and CD'ing to it.              *
  508. ***************************************************************************************
  509. Get_Path_And_Change_Do_It
  510.     Sub.l    d0,d0            Abort if there isn't a source lister.
  511.     Bsr    GetSourceHandle        Source handle -> Source_Handle(a5)
  512.  
  513.     Lea    Source_Handle(a5),a0    Handle to get path of.
  514.     Lea    PathBuffer1(a5),a1    -._ Buffer to
  515.     Move.w    #PathBuffer1Len,d7    -'  write into.
  516.     Bsr    GetListerPath        Lister path -> PathBuffer1(a5)
  517. ;-------------------------------------------------------------------------------------;
  518.     Tst.l    Quiet_S(a5)        -._ Skip output of new dir
  519.     Bne.s    Quiet_Skip        -'  if "Quiet" switch given.
  520.  
  521.     Lea    PathBuffer1(a5),a0    New path...
  522.     Move.l    a0,d2            To d2 to CLIRit2
  523.     Bsr    NullLen            Find length...
  524.     Move.l    d0,d3            ...to d3.
  525.     Bsr    CLIRit2            Output to the shell.
  526.     Lea    Return_Char(pc),a0    -.
  527.     Moveq    #Return_Char_Len,d3     |- Write a return after it.
  528.     Bsr    CLIRite            -'
  529.     Bra.s    Quiet_Skip
  530. Return_Char
  531.     Dc.b    10
  532. Return_Char_Len Equ *-Return_Char
  533.     Even
  534. Quiet_Skip
  535. ;-------------------------------------------------------------------------------------;
  536. ; For CD to be complete, must call BOTH SetCurrentDir() and SetCurrentDirName()          ;
  537. ;-------------------------------------------------------------------------------------;
  538.     Bsr    Create_NIB        Create a new NudelInfoBlock for Lock()ing...
  539.     Move.l    Active_NIB(a5),a1    NIB Pointer to a1
  540.     Move.l    a1,CD_NIB(a5)        Store our NIB pointer.
  541.  
  542.     Lea    PathBuffer1(a5),a2    -._ Pointer to returned path as
  543.     Move.l    a2,NIB_NameAdrs(a1)    -'  the filename of our new NIB.
  544.  
  545.     Move.l    CD_NIB(a5),Active_NIB(a5)    Make it active.
  546.     Moveq    #ACCESS_READ,d2            Do a read (shared) lock.
  547.     Bsr    Lock_NIB            Get a lock() on the path.
  548.     Tst.l    d0
  549.     Beq_ErrorE    ErrAct_Lock(pc),Active_NIB(a5)
  550.  
  551.     Move.l    CD_NIB(a5),a0
  552.     Move.l    NIB_Lock(a0),d1
  553.     N_CallDOS    CurrentDir    Set new current dir.
  554.     Move.l    CD_NIB(a5),a0
  555.     Move.l    d0,NIB_Lock(a0)        Replace lock with the old CD's lock.
  556. ;;;;;;;    (We must unlock the OLD CD's lock, but not the lock of the CD we set)
  557.     Move.l    CD_NIB(a5),Active_NIB(a5)    -._ Delete the CD_NIB, which
  558.     Bsr    Delete_NIB            -'  includes UnLock()'ing.
  559. ;-------------------------------------------------------------------------------------;
  560.     Lea    PathBuffer1(a5),a0
  561.     Move.l    a0,d1                New dir path -> d1 for SetCDN()
  562.     Move.l    d1,NIB_NameAdrs+FakeNIB(a5)    Set pseudo-filename in FakeNIB.
  563.     N_CallDOS    SetCurrentDirName
  564.     Tst.l    d0
  565.     Beq_ErrorE    ErrAct_SetCurrentDirName(pc),FakeNIB_Adrs(a5)
  566. ;-------------------------------------------------------------------------------------;
  567.     RTS
  568.  
  569. ErrAct_SetCurrentDirName
  570.     Dc.b    "Could not set current directory name",0
  571.     Even
  572.  
  573. ***************************************************************************************
  574. * Routine for getting the current dir and openning a new Lister in it.              *
  575. ***************************************************************************************
  576. ;-------------------------------------------------------------------------------------;
  577. ErrAct_GetCurrentDirName
  578.     Dc.b    "Could not find the current directory",0
  579.     Even
  580. ;=====================================================================================;
  581. ; ReadSource variant.                                      ;
  582. ;=====================================================================================;
  583. Get_CD_And_Open_Do_It_ReadSource
  584.     Moveq    #1,d0            Open new source if one doesn't exist.
  585.     Bsr    GetSourceHandle            Source handle -> Source_Handle(a5)
  586.     Bra.s    Get_CD_And_Open_Do_It_Read_Main    Rest as for ReadDest
  587.  
  588. ;=====================================================================================;
  589. ; ReadDest variant.                                      ;
  590. ;=====================================================================================;
  591. Get_CD_And_Open_Do_It_ReadDest
  592.     Moveq    #1,d0            Open new dest if one doesn't exist.
  593.     Lea    Source_Handle(a5),a1        -.
  594.     Move.w    #Source_HandleLen,d7         |- Dest handle -> Source_Handle(a5)
  595.     Bsr    GetDestHandle_ToBuffer        -'
  596. Get_CD_And_Open_Do_It_Read_Main
  597.     Bsr    DOpusFront            DOpus screen to front.
  598.     Bsr.s    Get_CD_And_Open_Get_Path    Path -> a0
  599.     Move.l    a0,a1                Path -> a1
  600.     Lea    Source_Handle(a5),a0        Handle -> a0
  601.     Sub.l    d0,d0                Don't force into current path buffer.
  602.     Bsr    ReadListerPath            Make the lister read the new path.
  603.     RTS
  604.  
  605. ;=====================================================================================;
  606. ; OpenLister variant.                                      ;
  607. ;=====================================================================================;
  608. Get_CD_And_Open_Do_It_OpenLister
  609.     Bsr.s    Get_CD_And_Open_Get_Path    Path -> a0
  610.     Move.l    Dimensions_K(a5),a1        Dimensions, or NULL (valid).
  611.     Lea    Source_Handle(a5),a2        -._ Buffer to write
  612.     Move.w    #Source_HandleLen,d7        -'  handle into.
  613.     Bsr    NewLister            Open the new lister.
  614. Get_CD_And_Open_MAIN
  615.     Lea    Source_Handle(a5),a0        Lister handle.
  616.     Sub.l    a1,a1                Default to "off" (not source or dest)
  617.     Sub.l    a2,a2                Default to "unlocked"
  618.  
  619.     Tst.l    Source_S(a5)            -.
  620.     Beq.s    Source_S_Skip             |- "Source", if requested,
  621.     Lea    Set_Source_SubCommand(pc),a1    -'  else check for "Dest"
  622.     Bra.s    Dest_S_Skip
  623. Source_S_Skip    
  624.     Tst.l    Dest_S(a5)            -.
  625.     Beq.s    Get_CD_ListerSet_Skip         |- "Dest", if requested,
  626.     Lea    Set_Dest_SubCommand(pc),a1    -'  else don't do a set at all.
  627. Dest_S_Skip
  628.     Tst.l    Lock_S(a5)            -.
  629.     Beq.s    Lock_S_Skip             |- "Lock", if requested.
  630.     Lea    Set_Lock_SubCommand(pc),a2    -'
  631. Lock_S_Skip
  632.     Bsr    ListerSet            Set Source/Dest/Lock.
  633. Get_CD_ListerSet_Skip
  634. ;-------------------------------------------------------------------------------------;
  635.     RTS
  636.  
  637. ;=====================================================================================;
  638. ; Point a0 to CD or Dir_S.                                  ;
  639. ;=====================================================================================;
  640. Get_CD_And_Open_Get_Path
  641.     Tst.l    Dir_K(a5)            Did they specify a directoy?
  642.     Bne.s    Get_CD_Use_Dir_K        If so, use it, else get CurrentDir.
  643.     Lea    PathBuffer1(a5),a0        -._ Buffer to write
  644.     Move.l    a0,d1                -'  CurrentDir into.
  645.     Move.l    #PathBuffer1Len,d2        Size of the Buffer.
  646.     N_CallDOS    GetCurrentDirName    CD -> Buffer.
  647.     Tst.l    d0
  648.     Beq_ErrorE    ErrAct_GetCurrentDirName(pc),#0
  649.     
  650.     Lea    PathBuffer1(a5),a0        Path to read.
  651.     RTS
  652. Get_CD_Use_Dir_K
  653.     Move.l    Dir_K(a5),a0            Path to read.
  654.     RTS
  655.  
  656. ***************************************************************************************
  657. * Routine for getting the Dest Lister's path and setting the CDOSource variable          *
  658. ***************************************************************************************
  659. Set_Dest_Env_Do_It
  660.     Sub.l    d0,d0            Abort if there isn't a dest lister.
  661.  
  662.     Lea    Source_Handle(a5),a1        -.
  663.     Move.w    #Source_HandleLen,d7         |- Dest handle -> Source_Handle(a5)
  664.     Bsr    GetDestHandle_ToBuffer        -'
  665.  
  666.     Lea    Source_Handle(a5),a0    Handle to get path of.
  667.     Lea    PathBuffer1(a5),a1    -._ Buffer to
  668.     Move.w    #PathBuffer1Len,d7    -'  write into.
  669.     Bsr    GetListerPath        Lister path -> PathBuffer1(a5)
  670. ;-------------------------------------------------------------------------------------;
  671.     Lea    Dest_Var_Name(pc),a0    Name of variable to set.
  672.     Bra.s    SSE_Com            Rest common to Set_Source_Env.
  673.  
  674. ***************************************************************************************
  675. * Routine for getting the Source Lister's path and setting the CDOSource variable     *
  676. ***************************************************************************************
  677. Set_Source_Env_Do_It
  678.     Sub.l    d0,d0            Abort if there isn't a source lister.
  679.     Bsr    GetSourceHandle        Source handle -> Source_Handle(a5)
  680.  
  681.     Lea    Source_Handle(a5),a0    Handle to get path of.
  682.     Lea    PathBuffer1(a5),a1    -._ Buffer to
  683.     Move.w    #PathBuffer1Len,d7    -'  write into.
  684.     Bsr    GetListerPath        Lister path -> PathBuffer1(a5)
  685. ;-------------------------------------------------------------------------------------;
  686. ; Now we set the variable.                                  ;
  687. ;-------------------------------------------------------------------------------------;
  688.     Lea    Source_Var_Name(pc),a0    -._ Name of
  689. SSE_Com    Move.l    a0,d1            -'  Variable
  690.     Lea    PathBuffer1(a5),a0    -._ Buffer containing
  691.     Move.l    a0,d2            -'  the path string.
  692.     Moveq    #-1,d3            Buffer is null-terminated.
  693.  
  694.     Move.l    #GVF_LOCAL_ONLY,d4    Specify local variable...
  695.     Tst.l    Global_S(a5)        Did they ask for a global variable?
  696.     Beq.s    SSEDING            If not, leave it as local.
  697.     Move.l    #GVF_GLOBAL_ONLY,d4    Else, set it to a global variable.
  698. SSEDING
  699.     Move.l    d1,NIB_NameAdrs+FakeNIB(a5)    Set pseudo-filename in FakeNIB.
  700.     N_CallDOS    SetVar            Set the variable.
  701.     Tst.l    d0
  702.     Beq_ErrorE    ErrAct_SetEnvVar(pc),FakeNIB_Adrs(a5)
  703.     RTS
  704.  
  705. Source_Var_Name
  706.     Dc.b    "CDOSource",0
  707. Dest_Var_Name
  708.     Dc.b    "CDODest",0
  709. ErrAct_SetEnvVar
  710.     Dc.b    "Could not set environment variable ",0
  711.     Even
  712.  
  713.  
  714. ***************************************************************************************
  715. * Routine for reading path into new Source lister, selecting files + running command. *
  716. ***************************************************************************************
  717. Do_Action_Do_It
  718.     Bsr    Get_CD_And_Open_Get_Path    Path -> a0
  719.     Move.l    Dimensions_K(a5),a1        Dimensions, or NULL (valid).
  720.     Lea    Source_Handle(a5),a2        -._ Buffer to write
  721.     Move.w    #Source_HandleLen,d7        -'  handle into.
  722.     Bsr    NewLister            Open the new lister.
  723.  
  724.     Lea    Source_Handle(a5),a0        Lister handle.
  725.     Lea    Set_Source_SubCommand(pc),a1    Make it the source lister.
  726.     Sub.l    a2,a2                ("unlocked")
  727.     Bsr    ListerSet            Set lister as Source
  728. ;-------------------------------------------------------------------------------------;
  729. ; If the path is buffered by Opus it could have some files selected, so command none. ;
  730. ;-------------------------------------------------------------------------------------;
  731.     Lea    Source_Handle(a5),a0        Lister handle.
  732.     Lea    Command_None_SubCommand(pc),a1    "none"
  733.     Sub.l    a2,a2                No second argument.
  734.     Bsr    ListerCommand            De-select all files.
  735.     Lea    Source_Handle(a5),a0        -._ Lister wait
  736.     Bsr    ListerWait            -'  is required.
  737.  
  738. ;-------------------------------------------------------------------------------------;
  739. ; Select files in the new lister if a pattern was given on the command line.          ;
  740. ;-------------------------------------------------------------------------------------;
  741.     Tst.l    ActPat_K(a5)        -._ Skip if no select
  742.     Beq.s    DADI_SP            -'  pattern given.
  743.  
  744.     Lea    Source_Handle(a5),a0            Lister handle
  745.     Lea    Command_Select_SubCommand(pc),a1    "select name"
  746.     Move.l    ActPat_K(a5),a2                Pattern to select.
  747.     Bsr    ListerCommand                Select the entries.
  748.     Lea    Source_Handle(a5),a0        -._ Lister wait
  749.     Bsr    ListerWait            -'  is required.
  750.  
  751.     Bra.s    DADI_SP
  752. Command_Select_SubCommand
  753.     Dc.b    "select name",0
  754. Command_None_SubCommand
  755.     Dc.b    "none",0
  756.     Even
  757. DADI_SP
  758. ;-------------------------------------------------------------------------------------;
  759. ; Issue command if one was given on the command line.                      ;
  760. ;-------------------------------------------------------------------------------------;
  761.     Tst.l    ActCom_K(a5)        -._ Skip if no
  762.     Beq.s    DADI_SK            -'  command given.
  763.  
  764.     Lea    Source_Handle(a5),a0    Lister handle.
  765.     Move.l    ActCom_K(a5),a1        Command to issue.
  766.     Sub.l    a2,a2            No second argument.
  767.     Bsr    ListerCommand
  768.  
  769. DADI_SK
  770. ;-------------------------------------------------------------------------------------;
  771. ; Close the lister now, if requested to (handles lister-wait by itself).          ;
  772. ;-------------------------------------------------------------------------------------;
  773.     Tst.l    ActClose_S(a5)        -._ Skip if not asked
  774.     Beq.s    DADI_SC            -'  to close the lister.
  775.     Lea    Source_Handle(a5),a0    Lister handle.
  776.     Bsr    ListerClose        Close the lister.    
  777. DADI_SC
  778. ;-------------------------------------------------------------------------------------;
  779.     RTS
  780. ***************************************************************************************
  781.